/*
 * PhaseUtils.cpp
 *
 *  Created on: 20 Aug 2011
 *      Author: Allan
 */

#include "PhaseUtils.h"

// Boost includes
#include <boost/foreach.hpp>

// GeoReact includes
#include "SpeciesUtils.h"

#include "../Phase.h"
#include "../Multiphase.h"
#include "../Activity/AqueousActivity.h"
#include "../Activity/GaseousActivity.h"
#include "../Activity/MineralActivity.h"

const Multiphase CreateMultiphase(const vector<string>& species)
{
	vector<Phase> phases;
	
	vector<string> aqueousSpecies = FilterSpecies(species, {"aqueous"});
	vector<string> gaseousSpecies = FilterSpecies(species, {"gaseous"});
	vector<string> mineralSpecies = FilterSpecies(species, {"mineral"});
	
	if(!aqueousSpecies.empty())
		phases.push_back(CreateAqueousPhase(aqueousSpecies));
	
	if(!gaseousSpecies.empty())
		phases.push_back(CreateGaseousPhase(gaseousSpecies));
	
	BOOST_FOREACH(const string& mineral, mineralSpecies)
		phases.push_back(CreateMineralPhase({mineral}));
	
	return Multiphase(phases);
}

const Phase CreateAqueousPhase(const vector<string>& species)
{
	return CreateAqueousPhase(species, AqueousActivity(species));
}

const Phase CreateAqueousPhase(const vector<string>& species, const AqueousActivity& activity)
{
	Phase phase;
	
	phase.SetName("Aqueous");
	phase.SetSpecies(species);
	phase.SetActivity(activity);
	
	return phase;
}

const Phase CreateGaseousPhase(const vector<string>& species)
{
	return CreateGaseousPhase(species, GaseousActivity(species));
}

const Phase CreateGaseousPhase(const vector<string>& species, const GaseousActivity& activity)
{
	Phase phase;
	
	phase.SetName("Gaseous");
	phase.SetSpecies(species);
	phase.SetActivity(activity);
	
	return phase;
}

const Phase CreateMineralPhase(const vector<string>& species)
{
	return CreateMineralPhase(species, MineralActivity(species));
}

const Phase CreateMineralPhase(const vector<string>& species, const MineralActivity& activity)
{
	Phase phase;
	
	phase.SetName("Mineral");
	phase.SetSpecies(species);
	phase.SetActivity(activity);
	
	return phase;
}
